home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr23
/
chansw53.zip
/
CHAIN5.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-24
|
3KB
|
129 lines
// FILE: CHAIN5.CPP
// MODULE: PASSWORD
// PROGRAM: CHAINSAW
// Public Domain, 5/24/93, 1993, Ted Davis
#include "chainsaw.hpp"
int ChangePassword(char * new_password, char *argv0, char * Switches)
// This is intentionally uncommented.
{
int handle, rcode = no;
char Key[password_len], Pword[password_len], Marker[Marker_len];
new_password[15] = '\0';
strcpy(Pword, new_password);
if((handle = _open(argv0, O_RDWR)) != -1)
{
if((lseek(handle, KeyOffset, SEEK_SET)) != -1)
{
if((read(handle, Key, password_len)) == password_len)
{
if((lseek(handle, ID_Offset, SEEK_END)) != -1)
{
if((read(handle, Marker, Marker_len)) == Marker_len)
{
Encrypt(Key, Marker, Marker_len);
if(!strncmp(Marker, MarkerText, Marker_len))
{
if((lseek(handle, PwordOffset, SEEK_END)) != -1)
{
Encrypt(Key, new_password, password_len);
if(((write(handle, new_password,\
password_len)) != -1) && ((write(handle,\
Switches, switches_len)) != -1))
{
rcode = yes;
}
}
}
else
{
if((lseek(handle, 0, SEEK_END)) != -1)
{
strncpy(Marker, MarkerText,16);
Encrypt(Key, Marker, Marker_len);
Encrypt(Key, Pword, password_len);
if(((write(handle, Marker, Marker_len))\
!= -1) && ((write(handle, Pword, password_len))\
!= -1) && ((write(handle,\
Switches, switches_len)) != -1))
{
rcode = yes;
}
}
}
}
}
}
}
if((_close(handle)) == -1)
{
rcode = no;
}
}
return(rcode);
}
int UserPassword(char * password, char * argv0, char * Switches, char * Pword)
// This is intentionally uncommented.
{
int handle, rcode = no;
char Key[password_len], Marker[Marker_len];
strncpy(Marker, MarkerText, 16);
if((handle = _open(argv0, O_RDONLY)) != -1)
{
if((lseek(handle, KeyOffset, SEEK_SET)) != -1)
{
if((read(handle, Key, password_len)) == password_len)
{
if((lseek(handle, ID_Offset, SEEK_END)) != -1)
{
if((read(handle, Marker, Marker_len)) == Marker_len)
{
Encrypt(Key, Marker, Marker_len);
if(!strncmp(Marker, MarkerText, Marker_len))
{
if((lseek(handle, PwordOffset, SEEK_END)) != -1)
{
read(handle, Pword, password_len);
read(handle, Switches, switches_len);
// Assuming that read does not fail may not
// be the best of ideas, but it does simplify
// the structure.
}
}
else
{
strcpy(Pword, PassWord);
Encrypt(Key, Pword, password_len);
strcpy(Switches, DefaultSwitchString);
}
Encrypt(Key, Pword, password_len);
if(!strcmp(Pword, ""))
{
rcode = yes;
}
else
{
if(!strcmp(Pword, password)) {rcode = yes;}
}
}
}
}
}
if((_close(handle)) == -1)
{
rcode = no;
}
}
return(rcode);
}